﻿import cgi
import datetime
import wsgiref.handlers
import os
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

##model part

class ExamModel(db.Model):
  examName = db.StringProperty(default='')
  courseName=db.StringProperty(default='')

class ClassModel(db.Model):
  className = db.StringProperty(default='')
  isActiveClass=db.StringProperty(default='N')
  schoolName = db.StringProperty(default='') ##not used yet
  gradeName = db.StringProperty(default='') ##not used yet

class StudentModel(db.Model):
  studentName = db.StringProperty(default='')
  studentNumber = db.IntegerProperty(default=0)
  studentMail = db.StringProperty(default='')
  studentSex = db.StringProperty(default='')
  className= db.StringProperty(default='')
  studentPassword = db.StringProperty(default='')

##class ParentModel(db.Model):
##  parentName = db.StringProperty(default='')
##  parentStudentNumber = db.IntegerProperty(default=0)
##  parentMail = db.StringProperty(default='')
##  studentName = db.StringProperty(default='')
##  className= db.StringProperty(default='')

class ExamRecordModel(db.Model):
  CourseName = db.StringProperty(default='')
  ExamName = db.StringProperty(default='')
  StudentNumber = db.IntegerProperty(default=0)
  RecordDate= db.DateTimeProperty(auto_now_add=True)
  RecordValue= db.StringProperty(default='')
  StudentOrderInExam=db.IntegerProperty(default=0)
  ClassName= db.StringProperty(default='')

def getActiveClass():
    try:
        classActive=ClassModel.all()
        classActive.filter('isActiveClass =','Y')
        if classActive.count()==0:
            return ''
        for classone1 in classActive:
            return classone1.className
    except:
        return 'getActiveClassFailed'

